getLocTime = function (timestamp) {
	timestamp = timestamp * 1000;
	var nTime = new Date().getTime();
	var split = nTime - timestamp;

	if (split <= 86400000 && split > 0)
	{
		var hours = split / 3600000;
		if (hours > 1)
		{
			var jstimestamp = "大约" + Math.round(hours) + "小时之前";
		}
		else{
			var min = split / 60000;

			var jstimestamp = "大约" + Math.round(min) + "分钟之前";
		}
	}
	else{
		var d = new Date(timestamp * 1); 
		var jstimestamp = (d.getFullYear())+"-"+rightStr("00"+(d.getMonth()+1).toString(), 2)+"-"+rightStr("00"+d.getDate().toString(), 2)+" "+(d.getHours())+":"+(d.getMinutes()); 
	}

	return jstimestamp; 
}

//选中/取消选中  某一排checkbox框
//参数names : 要选中的或取消的checkbox的name 如'uid[]'
//参数stateboxid	:	做为参照的checkbox的id ,如'selectAll'
/*EX:
<input type='checkbox' id='states' onclick='selectAll('id[]','states')'>
<form ...>
<input type='checkbox' name='id[]' value='1'>
<input type='checkbox' name='id[]' value='2'>
</form>
*/
selectAll=function(names,stateboxid)
{
	$$("input[name='"+names+"']").invoke("writeAttribute","checked",$(stateboxid).checked);
}

makeSelection = function (target, data) {
	var element = $('#' + target)[0];
	var select = arguments[2] ? arguments[2] : null;

	for (var i = 0;i < data.length ;i++ )
	{
		if (typeof(data[i]) == 'object')
		{
			var newOpt = new Option(data[i].name, data[i].value);
		}
		else{
			var newOpt = new Option(data[i], i);
		}
		element.options[element.options.length] = newOpt;
		
		if (i == select) {
			element.options[element.options.length-1].selected = true;
		}
	}
}

getRadioValue = function (frmName, id) {
	var elements = Form.getInputs(frmName, 'radio', id);
	
	for (var i = 0;i < elements.length ;i++ )
	{
		if (elements[i].checked)
		{
			return elements[i].value;
		}
	}

	return -1;
}

getCheckboxValue = function (names) {
	var elements = document.getElementsByName(names);
	var cbValue = '';
	
	for (var i = 0;i < elements.length ;i++ )
	{
		if (elements[i].checked)
		{
			 cbValue+= elements[i].value + ',';
		}
	}

	return cbValue;
}

getMulitValue = function (names) {
	var elements = document.getElementsByName(names);
	var cbValue = '';
	
	for (var i = 0;i < elements.length ;i++ )
	{
		if (elements[i].value != '')
		{
			 cbValue+= elements[i].value + ',';
		}
	}

	return cbValue;
}

rightStr = function (mainStr, lngLen) {
	if (mainStr.length-lngLen>=0 && mainStr.length>=0 && mainStr.length-lngLen<=mainStr.length) {
		return mainStr.substr(mainStr.length-lngLen,lngLen);
	}
	else{
		return null;
	}
}

loadScript = function (scriptPath) {
	var HashPath = scriptPath.toLowerCase().replace(/\//g, '').replace(/\./g, '');
	
	if (!$('#'+HashPath).length){
		var s = document.createElement("script");
		s.setAttribute("src", scriptPath);
		s.setAttribute("id", HashPath);
		document.body.appendChild(s);
	}
}

loadStyle = function (stylePath){
	var HashPath = stylePath.toLowerCase().replace(/\//g, '').replace(/\./g, '');
	
	if (!$('#'+HashPath).length){
		var s = document.createElement("link");
		s.rel 	= 'stylesheet';
		s.type	= 'text/css';
		s.href	= stylePath;
		s.id	= HashPath;
		document.body.appendChild(s);
	}
}

// Function Name: len
// Function Description: 返回字符串的实际长度, 一个汉字算2个长度
lenStr = function(str)
{
	return str.replace(/[^\x00-\xff]/g, "**").length;
}

readCookie = function (name)
{
	var cookieValue = "";
	var search = name + "=";

	if(document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);

		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end));
		}
	}

	return cookieValue;
}

/**
* 写Cookie
* argument[0] = name
* argument[1] = value
* argument[2] = hours
* argument[3] = path
* argument[4] = domain
* argument[5] = secure
*/
writeCookie = function (name, value)
{
	var expires = null;
	var argv = arguments;
	var argc = argv.length;
	var hours = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(hours!=null) expires = new Date((new Date()).getTime() + hours * 3600000);

	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expires.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}

var provinceIndex = '';

locateSel = function ()
{
	nobj = citySelction.startP; 

	if ($('#city' + provinceIndex))
	{
		$('#city' + provinceIndex).toggle();
	}

	provinceIndex = nobj.selectedIndex - 1;
	if ($('#city' + provinceIndex)[0])
	{
		$('#city' + provinceIndex).toggle();
	}
	else{
		var Statypes = city[provinceIndex];
		var reslocateID1HTML = "";
		if(typeof(Statypes)!='string') return;
		StatypeArray = Statypes.split(",");

		reslocateID1HTML="<select id='city"+provinceIndex+"' name='"+provinceIndex+"'><option value=-1>请选择城市</option>";
		for(i=0;i<StatypeArray.length;i++)
		{
			reslocateID1HTML=reslocateID1HTML+"<option value='"+StatypeArray[i]+"'>"+StatypeArray[i]+"</option>";
		}
		reslocateID1HTML=reslocateID1HTML+"</select>";

		citySelction.cityP.html(reslocateID1HTML);
	}
}

citySelction = {
	startP : null,
	cityP : null,

	setup : function (name, city) {
		citySelction.cityP = $('#' + city);
		citySelction.startP = $('#' + name)[0];

		makeSelection(name, province);

		$('#' + name).bind('change', locateSel);
	}
}

function addBookmark(title,url) { 
	if (window.sidebar) { 
		window.sidebar.addPanel(title,url,""); 
	} else if( document.all ) { 
		window.external.AddFavorite(url,title); 
	} else if( window.opera && window.print ) { 
		return true; 
	} 
} 